
#pragma once

#include <assert.h>

class RefCnt {
public:
    RefCnt() : mCnt(1) {}
    virtual ~RefCnt() { assert(mCnt == 1); }
    void ref() { mCnt ++; }
    void unref() const {
        if (this) {
            mCnt --;
            if (mCnt <= 0) {
                mCnt = 1;
                delete this;
            }
        }
    }

private:
    mutable int mCnt;
};


